﻿using Game.Map;
using Game.Objects;
using Game.Types;

namespace Game.Command.Internal
{
    public class BuildUnitScheduler : SchedulerCommand
    {
        readonly GameBuilding _GameBuilding;
        readonly IGameMap _GameMap;

        public BuildUnitScheduler(
            GameBuilding gameBuilding,
            IGameMap map)
        {
            _GameBuilding= gameBuilding;
            _GameMap = map;
            _GameBuilding.Tank.Changed += (sender, args) => Update();
            Update();
        }

        void Update()
        {
            base.IsEnabled = true;
        }

        public override string Name
        {
            get { return "Build "; }
        }

        public GameBuilding GameBuilding
        {
            get { return _GameBuilding; }
        }

        public override ScheduledCommand CreateScheduledCommand(VehicleType vehicle)
        {
            _GameBuilding.Tank.Decrease(vehicle.Cost);

            return new BuildUnitScheduledCommand(
                _GameBuilding, _GameMap, vehicle, this);
        }

    }

}

